package com.wmjsoft.plugins.nutzplugin.dao

import com.wmjsoft.plugins.nutzplugin.utils.ClassUtil
import org.nutz.dao.Chain
import java.lang.reflect.Field

class Updater(private var mySql:QueerSql) {




    operator fun set(filed: String?, value: Any?): Updater {
        if (null == this.mySql.chain) {
            this.mySql.chain  = Chain.make(filed, value)
        } else {
            this.mySql.chain!!.add(filed, value)
        }
        return this
    }

    fun <T> set(t: T): Updater {
        if (null == this.mySql.chain) {
            this.mySql.chain = Chain.from(t)
        }
        return this
    }


    fun <T> setTtoFiled(t: T): Updater {
        val fs: Array<Field> = t!!::class.java.declaredFields
        for (f in fs) {
            val fieldName = f.name
            val value: Any = ClassUtil.getProperty(t, fieldName)
            if (null != value) {
                this[fieldName] = value
            }
        }
        return this
    }

    fun where(): Wherer {
        return Wherer(this.mySql)
    }

}